import { http } from "@/utils/http";
import type { SREntity } from "@/api/entity";
import type { PDataRes, PListRes, SRPage } from "@/api/response";

export type MenuType = "M" | "C" | "F";

export type SysMenu = SREntity & {
  menuId: string;
  title: string;
  lngTitle: Record<string, string>;
  menuType: MenuType;
  icon: string;
  pid: string;
  path: string;
  routeName: string;
  routePath: string;
  component: string;
  isFrame: boolean;
  frameUrl: string;
  isHide: number;
  redirect?: string;
  mobileTab: number;
  mobileTabOrder: number;
  children?: SysMenu[];
};

export const getMenuList = (
  req: SRPage & SysMenu
): Promise<PListRes<SysMenu>> => {
  return http.get("/api/v1/sys/sysMenu/list", { params: req });
};

export const getMenuTree = (
  req: SRPage & SysMenu
): Promise<PDataRes<SysMenu[]>> => {
  return http.get("/api/v1/sys/sysMenu/tree", { params: req });
};

export const getMenu = (menuId: string): Promise<PDataRes> => {
  return http.get(`/api/v1/sys/sysMenu/${menuId}`);
};

export const createMenu = (data: SysMenu): Promise<PDataRes> => {
  return http.post("/api/v1/sys/sysMenu", { data });
};

export const updateMenu = (data: SysMenu): Promise<PDataRes> => {
  return http.put("/api/v1/sys/sysMenu", { data });
};

export const deleteMenu = (menuId: string): Promise<PDataRes> => {
  return http.delete(`/api/v1/sys/sysMenu/${menuId}`);
};
